﻿<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="IP_PROJECT._Default" %>

<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
    <hgroup class="title">
        <h1>Latest articles.</h1>
    </hgroup>
    <asp:Repeater ID="ArticleRepeater" runat="server" DataSourceID="AllArticlesSqlSource">
        <ItemTemplate>
            <p>
                <h3>
                    <asp:LoginView id="AdminView" runat="server">
                        <RoleGroups>
                            <asp:RoleGroup Roles="Admin">
                                <ContentTemplate>
                                    <asp:Button ID="DeleteArticle" runat="server" Text="x" CommandArgument='<%# Eval("Id") %>' OnClick="DeleteArticle_Click" />
                                </ContentTemplate>
                            </asp:RoleGroup>
                        </RoleGroups>
                    </asp:LoginView>
                    <%# Eval("Title") %>
                </h3>
                <%# Eval("Description") %>
                <a href="Article.aspx?Id=<%# Eval("Id") %>">Read more...</a>
            </p>
        </ItemTemplate>
    </asp:Repeater>
    <asp:LoginView id="AddNewArticleView" runat="server">
        <RoleGroups>
            <asp:RoleGroup Roles="Admin">
                <ContentTemplate>
                    <h4>Add new article</h4>
                     <p>
                         <b>Title</b>
                         <asp:TextBox ID="ArticleTitle" runat="server" Text='<%# Eval("Title") %>'/>
                     </p>
                     <b>Description:</b>
                     <p>
                         <asp:TextBox ID="ArticleDescription" runat="server" Text='<%# Eval("Description") %>' TextMode="MultiLine" />
                     </p>
                         <b>Content:</b>
                     <p>
                         <asp:TextBox ID="ArticleContent" runat="server" Text='<%# Eval("Content") %>' TextMode="MultiLine" />
                     </p>
                     <asp:Button ID="SaveArticle" runat="server" Text="Save" OnClick="SaveArticle_Click" />
                </ContentTemplate>
            </asp:RoleGroup>
        </RoleGroups>
     </asp:LoginView>
    <asp:SqlDataSource runat="server" ID="AllArticlesSqlSource" ConnectionString='<%$ ConnectionStrings:DefaultConnection %>' SelectCommand="SELECT [Id], [Title], [Description] FROM [Articles] ORDER BY [Id] DESC"></asp:SqlDataSource>
</asp:Content>
